"""
@Filename: core/ddt_util.py
@Author: yoko
@Time: 2023/5/23 16:25
@Describe: ...
"""
import re
from io import StringIO

import yaml


def ddt(caseinfo):
    yaml_str=yaml.dump(caseinfo)
    # 正则提取
    args_list = re.findall('\\$ddt\\{(.*?)\\}', yaml_str)
    print(args_list)
    lists=[]
    dicts_list=[]
    for i in range(1,len(caseinfo["parametrizes"])):
        yaml_str1=yaml_str
        for arg in args_list:
            old_str='$ddt{'+arg+'}'

            index=caseinfo["parametrizes"][0].index(arg)
            new_str=caseinfo["parametrizes"][i][index]

            yaml_str1=yaml_str1.replace(old_str,new_str)
        lists.append(yaml_str1)
    for list in lists:
        yaml_dict=yaml.safe_load(StringIO(list))
        dicts_list.append(yaml_dict)
    return dicts_list

